home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
Softshoe
/
Lisa's Mac Parts
/
Files
/
Directories
/
CatInfo.cp
< prev
next >
Wrap
Text File
|
2000-06-23
|
6KB
|
263 lines
// CatInfo.cp
#ifndef CatInfo_h
#include "CatInfo.h"
#endif
#ifndef FileNotFoundError_h
#include "FileNotFoundError.h"
#endif
#ifndef DirectoryNotFoundError_h
#include "DirectoryNotFoundError.h"
#endif
#ifndef HardwareVolumeLockError_h
#include "HardwareVolumeLockError.h"
#endif
#ifndef SoftwareVolumeLockError_h
#include "SoftwareVolumeLockError.h"
#endif
#ifndef FileLockError_h
#include "FileLockError.h"
#endif
#ifndef FilePermissionError_h
#include "FilePermissionError.h"
#endif
#ifndef NotADirectoryError_h
#include "NotADirectoryError.h"
#endif
#ifndef BadFileNameError_h
#include "BadFileNameError.h"
#endif
CatInfo::CatInfo()
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
}
CatInfo::CatInfo( const FileLocation& target )
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
Get( target );
}
CatInfo::CatInfo( ::Directory directory )
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
Get( directory );
}
CatInfo::CatInfo( ::Directory directory, ConstPString name )
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
Get( directory, name );
}
CatInfo::CatInfo( ::Directory directory, int16 index )
{
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
Get( directory, index );
}
CatInfo::CatInfo( const CInfoPBRec& info )
{
Assert( info.hFileInfo.ioNamePtr != 0 );
*static_cast<CInfoPBRec *>( this ) = info;
hFileInfo.ioCompletion = 0;
hFileInfo.ioNamePtr = location.name;
hFileInfo.ioFVersNum = 0;
location.vRefNum = hFileInfo.ioVRefNum;
location.parID = hFileInfo.ioFlParID;
location.SetName( info.hFileInfo.ioNamePtr );
}
CatInfo::CatInfo( const CatInfo& source )
: CInfoPBRec( source ),
location( source.location )
{
hFileInfo.ioNamePtr = location.name;
}
void CatInfo::operator=( const CatInfo& source )
{
static_cast< CInfoPBRec& >( *this ) = source;
location = source.location;
hFileInfo.ioNamePtr = location.name;
}
void CatInfo::Get()
{
hFileInfo.ioVRefNum = location.Volume().RefNum();
hFileInfo.ioDirID = location.ParentID().Number();
hFileInfo.ioFDirIndex = 0;
ThrowError( PBGetCatInfoSync( this ) );
Assert( hFileInfo.ioVRefNum == location.vRefNum );
Assert( hFileInfo.ioFlParID == location.parID );
}
void CatInfo::Get( const FileLocation& target )
{
location = target;
Get();
}
void CatInfo::Get( ::Directory directory )
{
hFileInfo.ioVRefNum = directory.Volume().RefNum();
hFileInfo.ioDirID = directory.ID().Number();
hFileInfo.ioFDirIndex = -1;
ThrowError( PBGetCatInfoSync( this ) );
location.vRefNum = hFileInfo.ioVRefNum;
location.parID = hFileInfo.ioFlParID;
}
void CatInfo::Get( ::Directory directory, ConstPString name )
{
location.Set( directory, name );
Get();
}
void CatInfo::Get( ::Directory directory, int16 index )
{
Assert( index > 0 );
hFileInfo.ioVRefNum = directory.Volume().RefNum();
hFileInfo.ioDirID = directory.ID().Number();
hFileInfo.ioFDirIndex = index;
ThrowError( PBGetCatInfoSync( this ) );
location.vRefNum = hFileInfo.ioVRefNum;
location.parID = hFileInfo.ioFlParID;
Assert( directory.Volume().RefNum() == location.vRefNum );
Assert( directory.ID().Number() == location.parID );
}
bool CatInfo::TryToGet( ::Directory directory, int16 index )
{
Assert( index > 0 );
hFileInfo.ioVRefNum = directory.Volume().RefNum();
hFileInfo.ioDirID = directory.ID().Number();
hFileInfo.ioFDirIndex = index;
OSErr error = PBGetCatInfoSync( this );
if ( error == fnfErr )
return false;
ThrowError( error );
location.vRefNum = hFileInfo.ioVRefNum;
location.parID = hFileInfo.ioFlParID;
Assert( directory.Volume().RefNum() == location.vRefNum );
Assert( directory.ID().Number() == location.parID );
return true;
}
bool CatInfo::TryToGet()
{
hFileInfo.ioVRefNum = location.Volume().RefNum();
hFileInfo.ioDirID = location.ParentID().Number();
hFileInfo.ioFDirIndex = 0;
OSErr error = PBGetCatInfoSync( this );
if ( error == fnfErr )
return false;
ThrowError( error );
return true;
}
bool CatInfo::TryToGet( const FileLocation& target )
{
location = target;
return TryToGet();
}
void CatInfo::Set()
{
hFileInfo.ioVRefNum = location.Volume().RefNum();
hFileInfo.ioDirID = location.ParentID().Number();
ThrowError( PBSetCatInfoSync( this ) );
}
void CatInfo::Set( const FileLocation& target )
{
location = target;
Set();
}
::Directory CatInfo::AsDirectory() const
{
if ( !IsDirectory() )
throw NotADirectoryError( noErr );
return ::Directory( location.Volume(), Directory().ID() );
}
void CatInfo::Up()
{
Assert( !IsRoot() );
if ( IsRoot() )
ThrowError( dirNFErr );
Get( location.Parent() );
}
void CatInfo::Down( ConstPString child )
{
Assert( IsDirectory() );
if ( !IsDirectory() )
throw NotADirectoryError( noErr );
location.SetParentID( Directory().ID() );
location.SetName( child );
Get();
}
void CatInfo::Sideways( ConstPString sibling )
{
location.SetName( sibling );
Get();
}
void CatInfo::SetLabel( uint8 label )
{
Assert( label < 8 );
hFileInfo.ioFlFndrInfo.fdFlags &= uint16( ~kColor );
hFileInfo.ioFlFndrInfo.fdFlags != label << 1;
}
void CatInfo::ThrowError( OSErr error )
{
if ( error == noErr )
return;
switch ( error )
{
case fnfErr: throw FileNotFoundError( error );
case dirNFErr: throw DirectoryNotFoundError( error );
case wPrErr: throw HardwareVolumeLockError( error );
case vLckdErr: throw SoftwareVolumeLockError( error );
case fLckdErr: throw FileLockError( error );
case afpAccessDenied: throw FilePermissionError( error );
case bdNamErr: throw BadFileNameError( error );
}
Assert( ("Unexpected error", 0) );
throw FileError( error );
}